import { debounce } from "lodash-es";

import type { ReactiveData } from "@/pages/room/model.ts";
import type { PlayerInst } from "@/pages/room/components/player/player.ts";
import type { ServerEventListener } from "@/pages/room/ws/ws.ts";

export function createVideoSeekedListener(
    data: ReactiveData,
    player: PlayerInst,
    triggerAfter: (operator: number, time: number) => void
): ServerEventListener<"video.seeked"> {
    return debounce((details) => {
        player.seek(details.time / 1000, true);
        triggerAfter(details.operator, details.time / 1000);
    }, 200);
}
